package com.zxl.live.screen.call.ui.widget;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;

import pl.droidsonroids.gif.GifDrawable;
import pl.droidsonroids.gif.GifImageView;

/**
 * Created by Administrator on 2017/12/23.
 */

public class GifAnimationView extends GifImageView {

    private GifDrawable mGifDrawable;

    public GifAnimationView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void setImageDrawable(Drawable drawable) {
        super.setImageDrawable(drawable);
        if (GifDrawable.class.isInstance(drawable)) {
            mGifDrawable = (GifDrawable) drawable;
        }
    }

    public void setCornerRadius(float cornerRadius) {
        if (mGifDrawable != null) {
            mGifDrawable.setCornerRadius(cornerRadius);
        }
    }

    public void stop() {
        if (null != mGifDrawable) {
            if (mGifDrawable.isRunning()) {
                mGifDrawable.seekToFrame(0);
            }
            mGifDrawable.stop();
            setImageBitmap(null);
            mGifDrawable = null;
        }
    }
}
